package com.corn.flink.lesson3;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2023/2/24 11:15
 */

public class FlinKReduceOperatorDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.fromElements(
                new Person("alice", 15, "cq"),
                new Person("jack", 18, "cq"),
                new Person("rose", 20, "sh"),
                new Person("mick", 42, "gz"),
                new Person("white", 12, "cq"),
                new Person("maria", 32, "sz"),
                new Person("candy", 56, "bj"),
                new Person("jerry", 28, "wh")
        ).keyBy(Person::getAddress)
                .reduce((p1, p2) -> {
                    p2.setName(p2.getName() + "," + p1.getName());
                    p2.setAge(p1.getAge() + p2.getAge());
                    return p2;
                })
                .print();
        env.execute();
    }

}
